local nianen = fk.CreateSkill {
  name = "nianen",
}

nianen:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  mute = true,
  prompt = "#nianen",
  interaction = function()
    local all_names = U.getAllCardNames("b")
    local names = U.getViewAsCardNames(Self, "nianen", all_names)
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter =function (self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    if use.card.name ~= "slash" or use.card.color ~= Card.Red then
      player:broadcastSkillInvoke(self.name, math.random(3, 4))
      room:invalidateSkill(player, self.name, "-turn")
      if not player:hasSkill("mashu", true) then
        room:handleAddLoseSkills(player, "mashu")
        room.logic:getCurrentEvent():findParent(GameEvent.Turn):addCleaner(function()
          room:handleAddLoseSkills(player, "-mashu")
        end)
      end
    else
      player:broadcastSkillInvoke(self.name, math.random(1, 2))
    end
  end,
  enabled_at_play = Util.TrueFunc,
  enabled_at_response = Util.TrueFunc,
})

return nianen